package com.rt.easyjava.base.biz1.bean.base;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.rt.easyjava.base.biz1.bean.TmptAuthDeptBiz;
import com.rt.easyjava.common.base.UserDetailsDto;
import lombok.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;


/**
 *
 * @author wuxiaoyong
 * @since 2020-11-28
 */

@Data
@ToString
@EqualsAndHashCode(callSuper = false)
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TmptAuthDept extends Model<TmptAuthDeptBiz>{

    private String deptLogo;
    private String address;
    private Integer govCmpy;
    private Integer level;
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    private Long parentId;
    private String name;
    private String number;
    private Integer tmptDeptType;
    private Integer deleteflag;
    private String createman;
    private Date modifydate;
    private String modifyman;
    private Date createdate;
    private Long companyId;
    private Long createmanId;
    private Long modifymanId;



    // 当树表时，用这个存储子树
    @TableField(exist = false)
    private List<TmptAuthDeptBiz> tmptAuthDeptList;


    // 重写这个方法，return当前类的主键
    @Override
    protected Serializable pkVal() {
        return id;
    }

    // set deleteflag default 0, 查询参数时，默认只查有效数据
    public void setDeleteflagDefaultZero(){
        if(this.deleteflag==null){
            this.setDeleteflag(0);
        }
    }

    // 数据访问边界 0：全部数据， 10：机构内部数据
    public void rebuildDataLimitQueryBean(UserDetailsDto userDetailsDto){
        if (userDetailsDto==null) return;
        int dataLimitType = userDetailsDto.getDataLimitType();
        if (dataLimitType >= 10) {
            this.setCompanyId(Long.parseLong(userDetailsDto.getCompanyId()));
        }
        if (dataLimitType >= 20) {
            this.setCreatemanId(Long.parseLong(userDetailsDto.getUserId()));
        }
    }

}
